//
// Created by miaomiaole on 2024/1/28.
//

#include <opencv2\opencv.hpp>

#include <iostream>
#include <opencv2\imgproc\types_c.h> //for CV_RGB2GRAY
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>

using namespace cv;

using namespace std;

void adaptive_threshold() {
    Mat srcImage = imread("./audisign.jpeg");
    imshow("srcImage", srcImage);

    Mat srcGray;
    cvtColor(srcImage, srcGray, CV_RGB2GRAY);
    imshow("srcGray", srcGray);
    Mat dstImage;
    const int maxVal = 255;
    int blockSize = 3;
    int constValue = 10;
    int adaptiveMethod = 0;
    int thresholdType = 1;

    // 图像自适应阈值操作
    adaptiveThreshold(srcGray, dstImage, maxVal, adaptiveMethod, thresholdType, blockSize, constValue);

    namedWindow("dstImage", WINDOW_NORMAL);

    imshow("dstImage", dstImage);

    waitKey(0);
}


void adaptive_threshold_2() {
    Mat img = imread("./IMG_20161003_182919.jpg");
    Mat dst1;
    Mat dst2;
    Mat dst3;
    //进行，灰度处理
    cv::cvtColor(img, img, COLOR_RGB2GRAY);
    //中值滤波
    medianBlur(img, img, 5);
    //阈值分割
    threshold(img, dst1, 127, 255, THRESH_BINARY);
    //自动阈值分割,邻域均值
    adaptiveThreshold(img, dst2, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 11, 2);
    //自动阈值分割，高斯邻域
    adaptiveThreshold(img, dst3, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 11, 2);
    namedWindow("dst1", WINDOW_NORMAL);
    namedWindow("dst2", WINDOW_NORMAL);
    namedWindow("dst3", WINDOW_NORMAL);
    namedWindow("img", WINDOW_NORMAL);
    imshow("dst1", dst1);
    imshow("dst2", dst2);
    imshow("dst3", dst3);
    imshow("img", img);
    waitKey(0);
}

int main() {
    // adaptive_threshold();
    adaptive_threshold_2();
}